home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / stdlib / rand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-09  |  669 b   |  41 lines

  1.  
  2.  
  3. /*
  4.  *  RAND.C
  5.  *
  6.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  7.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  8.  *    DICE-LICENSE.TXT.
  9.  */
  10.  
  11. #include <stdlib.h>
  12.  
  13. int  _RandSeed1 = 0;
  14. int  _RandSeed2 = 0;
  15.  
  16. static __autoinit void
  17. rand_init()
  18. {
  19.     srand(1);
  20. }
  21.  
  22. int
  23. rand(void)
  24. {
  25.     _RandSeed1 = ((_RandSeed1 * 13 + 1) ^ (_RandSeed1 >> 9)) + _RandSeed2;
  26.     _RandSeed2 = (_RandSeed2 * _RandSeed1 + 13) ^ (_RandSeed2 >> 13);
  27.     return(_RandSeed1 & RAND_MAX);
  28. }
  29.  
  30. void
  31. srand(seed)
  32. unsigned int seed;
  33. {
  34.     _RandSeed1 = (seed - 1) ^ 0xAB569834;
  35.     _RandSeed2 = (seed + 1) ^ 0x56F42001;
  36.     rand();
  37.     rand();
  38.     rand();
  39. }
  40.  
  41.